<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>
	
	Creating Outlook Tasks with PHP - The Glass is Too Big - J Wynia

</title>
	<link href="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/screen.css" rel="stylesheet" type="text/css" media="screen">
	<link href="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/print.css" rel="stylesheet" type="text/css" media="print">
	<!--[if lt IE 8]>
		<link href="/Content/blueprint/ie.css" rel="stylesheet" type="text/css" />
	<![endif]-->
	<link href="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/Site.css" rel="stylesheet" type="text/css">
	<script src="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/ga.js" async="" type="text/javascript"></script><script src="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/jquery-1.js" type="text/javascript"></script>
	<script src="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/jquery.htm" type="text/javascript"></script>
	<script src="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/jquery.js" type="text/javascript"></script>
	<script src="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/jquery_002.htm" type="text/javascript"></script>

    <link href="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/css_002.css" rel="stylesheet" type="text/css"><link href="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/css_003.css" rel="stylesheet" type="text/css"><link href="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/css.css" rel="stylesheet" type="text/css"><meta name="google-site-verification" content="rOO6Rnkd59a0UMv9O5NE4Vyu6bw3OkgBoVuxQzNE8ww"><link rel="alternate" type="application/rss+xml" title="The Glass is Too Big - Latest" href="http://feeds.wynia.org/JWynia"><link rel="alternate" type="application/rss+xml" title="J Wynia's Bookmarks" href="http://feeds.wynia.org/JWyniaBookmarks"><link rel="alternate" type="application/rss+xml" title="J Wynia's Latest Twitter Postings" href="http://feeds.wynia.org/Twitter/JWynia"><script src="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/embed.js" async="" type="text/javascript"></script></head>
<body>
	 <div class="container" id="BodyContainer">

        <div class="span-24 last" id="MainContentContainer">

            <div class="span-24 last container">

                <div class="span-16">

		

    
        <h1>Creating Outlook Tasks with PHP</h1>
    
    
    <p> 
        <i>Originally published: 02/2006 by J Wynia</i>
    </p>
    <div class="ArticleContent">
        Last week I posted a script I'm using to make it easier to <a href="http://www.wynia.org/wordpress/2006/02/02/lifehack-creating-weekly-status-reports-with-php/">create a weekly milestone/status report</a>. In my case, it's a specific client that wants these, but I know lots of employees who are required to do them as well. 
<br><p>Here's another piece in what is shaping up to be a string of 
tools for managing this kind of thing. This creates an Outlook task for 
taking daily notes on what happened each day. It will be run each Monday
 to create a task with a due date of Friday. The subject will contain 
the dates for the Sun-Sat current week.
<br></p><p>It also serves as a fairly simple example of creating tasks 
in Outlook automatically. The code is commented to explain what's going 
on. As with the previous solution, I'm using the Windows task scheduler 
to have this kick off on Monday morning. I'll likely write something up 
to easily "self-schedule" as well as I am already irritated at having to
 manually set these up even the once. (I know, low tolerance for 
irritability).
<br></p><p><code><font color="#000000"> </font><font color="#0000CC">&lt; ?php <br></font><font color="#FF9900">/* Define Outlook number for Task Item */<br></font><font color="#0000CC">$olTaskItem </font><font color="#006600">= </font><font color="#0000CC">3</font><font color="#006600">; <br> <br></font><font color="#FF9900">/* Create an instance of Outlook */ <br></font><font color="#0000CC">$ol </font><font color="#006600">= new </font><font color="#0000CC">COM</font><font color="#006600">(</font><font color="#CC0000">"Outlook.Application"</font><font color="#006600">); <br><br></font><font color="#FF9900">/* Create a Task Item */<br></font><font color="#0000CC">$task </font><font color="#006600">= </font><font color="#0000CC">$ol</font><font color="#006600">-&gt;</font><font color="#0000CC">CreateItem</font><font color="#006600">(</font><font color="#0000CC">$olTaskItem</font><font color="#006600">); <br><br></font><font color="#FF9900">/* <br>Set dates for current week. <br>PHP's strtotime needs the chosen strings to give us the Sun-Sat week. <br>If you choose to use a Mon-Fri week, the "last" becomes "this" for the beginning. <br>It's just how PHP and strtotime work. <br>*/ <br></font><font color="#0000CC">$begin </font><font color="#006600">= </font><font color="#0000CC">date</font><font color="#006600">(</font><font color="#CC0000">"m/d/y"</font><font color="#006600">, </font><font color="#0000CC">strtotime</font><font color="#006600">(</font><font color="#CC0000">"last Sunday"</font><font color="#006600">)); <br></font><font color="#0000CC">$end </font><font color="#006600">= </font><font color="#0000CC">date</font><font color="#006600">(</font><font color="#CC0000">"m/d/y"</font><font color="#006600">, </font><font color="#0000CC">strtotime</font><font color="#006600">(</font><font color="#CC0000">"this Saturday"</font><font color="#006600">)); <br></font><font color="#0000CC">$due </font><font color="#006600">= </font><font color="#0000CC">date</font><font color="#006600">(</font><font color="#CC0000">"m/d/y"</font><font color="#006600">, </font><font color="#0000CC">strtotime</font><font color="#006600">(</font><font color="#CC0000">"this Friday"</font><font color="#006600">)); <br> <br></font><font color="#FF9900">/* Set some properties of the task */ <br></font><font color="#0000CC">$task</font><font color="#006600">-&gt;</font><font color="#0000CC">Subject </font><font color="#006600">= </font><font color="#CC0000">"Milestone Notes for $begin to $end"</font><font color="#006600">; <br></font><font color="#0000CC">$task</font><font color="#006600">-&gt;</font><font color="#0000CC">DueDate </font><font color="#006600">= </font><font color="#0000CC">$due</font><font color="#006600">; <br></font><font color="#0000CC">$task</font><font color="#006600">-&gt;</font><font color="#0000CC">Body </font><font color="#006600">= </font><font color="#CC0000">"Insert the template text for your task"</font><font color="#006600">; <br> <br></font><font color="#FF9900">/* Save the Task */ <br></font><font color="#0000CC">$task</font><font color="#006600">-&gt;</font><font color="#0000CC">Save</font><font color="#006600">(); <br> <br>print(</font><font color="#CC0000">"Done"</font><font color="#006600">); <br></font><font color="#0000CC">?&gt;</font>
<br></code>
<br></p><p>If you're curious about modifying the task a little more, you
 can see the complete list of properties (Subject, Body, DueDate, etc.) 
and Methods (like Save) in the <a href="http://msdn.microsoft.com/library/en-us/vbaol11/html/olobjTaskItem_HV05247372.asp?frame=true">Outlook documentation for the TaskItem</a>.
 Most of the examples are in VBScript, but that's generally the case 
with Office documentation. However, use my sample script as your guide 
and you can pretty quickly see the syntax conversion you need to do to 
make their examples work (is there interest in a post showing how to 
more generally convert VBScript or Javascript into PHP?).
    </p></div>
    <div class="ArticleMeta">
        Tags: 
    </div>
            <h3>Comments</h3>
            

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      Chase on 2/18/2006                      
                  </div>
                    I am in IT for small company and our internal 
software is all done in PHP. I know PHP very well, but my knowledge of 
COM stuff is very weak. Our telephone system (Televantage) has a great 
API for doing all sorts of stuff, but its all COM based. There were a 
few sample scripts (VB i believe) but was having trouble implementing 
them in ASP (which I dont know well at all) and I really am struggling 
with trying to take those scripts and convert them for use in PHP with 
the COM object. So any help you could give would be great. Also, is it 
possible to create a task in outlook and assign it to someone else? We 
want our managers to be able to mark an item for an employee, and have 
it auto generate an outlook task for that employee.

Thanks for your help
                    
                  </div>

                

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      J Wynia on 2/19/2006                      
                  </div>
                    I did start on my "porting ASP to PHP" article, and 
I'll work on finishing it up when I get a chance. If you can send me a 
link to their documentation, I might be able to use it as an example in 
my posting using their objects.

The biggest syntax change is that PHP uses $object-&gt;property syntax 
while VBScript uses object.property. Also, whenever you see a constant 
like

myOlApp.CreateItem(olTaskItem)

the "olTaskItem" is a constant that you'll have to look up. The constant
 is often just "there" if you're doing it in VBA, but in PHP, you'll 
need the actual value of "3" instead.

In Outlook, you can defintely assign tasks. Effectively, you can do 
pretty much anything with COM in Outlook that you can do manually. 
That's really the power of the automation stuff. In the above code, once
 you reach the point where you're setting properties:

$task-&gt;Subject = "Subject";

The variable $task is what the Outlook object model calls an "Item". 
It's specifically a TaskItem. If you look in the Outlook documentation 
at the object "TaskItem", you will see all of the properties and methods
 you can use on a task.

The Outlook object model is described here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_2003_ta/html/odc_landoffice03_vba.asp

TaskItems
 are described here:
http://msdn.microsoft.com/library/en-us/vbaol11/html/olobjTaskItem_HV05247372.asp?frame=true

Down
 at the bottom of that documentation page is a huge list of those 
properties an methods. "Save()" is one of those that I used in my 
sample. For your project, you'll want to look at "Assign" to send them 
out and possibly "Mark Complete" and "Delete" if you want to cancel from
 the same place you're assigning.

Take a look at the VB examples and compare them with my PHP above and 
you should see the patterns you'll need to convert all of the example 
code into PHP.

Oh. You may also need to install a program that I don't have the 
name/URL of handy that overrides Outlook's tight security to enable your
 app to really dig into Outlook.
                    
                  </div>

                

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      leonardo on 3/9/2006                      
                  </div>
                    How I get the number for OlForderContacts? because I got this error when I tried to use other folder.

Warning: (null)(): Invoke() failed: Type mismatch. Argument: 2
                    
                  </div>

                

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      J Wynia on 3/9/2006                      
                  </div>
                    All of the outlook constants are defined in the documentation I linked to.
                    
                  </div>

                

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      John on 3/20/2006                      
                  </div>
                    Hi!

i have tested this code but i think there is something wrong. i have 
outlook 2003, win xp, and php 4, is there any issue with outlook 2003 
and the foloing code?

sorry about my english (i'm portugese)

thanks ;)
                    
                  </div>

                

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      Peter Winch on 4/17/2006                      
                  </div>
                    Hi,

Need to know where I can find list of valid commands, ie, Worksheet-&gt;Add(); for excel COM objects.

Can you help?
                    
                  </div>

                

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      J Wynia on 4/17/2006                      
                  </div>
                    Just go up the tree from the documentation I linked to. All of the Office objects are there.
                    
                  </div>

                

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      seo on 5/27/2006                      
                  </div>
                    this code seems to working for me. cheers!
                    
                  </div>

                

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      Problem :Create an instance of Outlook on 6/30/2006                      
                  </div>
                    I am trying only the code 


But getting the error as :

Fatal error: Uncaught exception 'com_exception' with message 'Failed to 
create COM object `Outlook.Application.11': Server execution failed ' in
 C:\Program Files\Apache Group\Apache2\htdocs\powerplate\test4.php:2 
Stack trace: #0 C:\Program Files\Apache 
Group\Apache2\htdocs\powerplate\test4.php(2): 
com-&gt;com('Outlook.Applica...') #1 {main} thrown in C:\Program 
Files\Apache Group\Apache2\htdocs\powerplate\test4.php on line 2


I have isntalled Windows XP / MSOutlook  2003 /Apache 2.054 /PHP 5.0.3

Please help
                    
                  </div>

                

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      egon muencberger on 4/5/2007                      
                  </div>
                    com functions are NOT available under a linux 
distribution - windows only, you will have to resort to an activeXObject
 instead!
                    
                  </div>

                

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      Pascal on 10/30/2007                      
                  </div>
                    hi there!

as i want to develop a webbased tool in PHP4, which sends tasks and 
meetings to my outlook as an email (as if somebody else would send me 
the task from his outlook), i wonder, how the task can be sent. 

i already managed to send me meetings with the vCalendar standard used 
in Outlook:
BEGIN: VEVENT
...
END: VEVENT

As in Outlook 2003 the VTODO does not exist, I don't know how to 
continue. 

Can anybody help me? Do I need to install someting particular on the 
webserver that I can make use of the Outlook Object with PHP?

Regards
Pascal
                    
                  </div>

                

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      Toby on 2/16/2008                      
                  </div>
                    This is great but can one do something fairly easy 
like loop through the tasks already present in Outlook and display them 
as a list on a webpage?
                    
                  </div>

                

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      ksign on 1/17/2008                      
                  </div>
                    very helpfull !!
I'm working on it, I might publish some more examples when I handle.
                    
                  </div>

                

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      Elaine on 2/2/2008                      
                  </div>
                    Hi, please help on this,

Unable to connect to Outlook: Failed to create COM object `Outlook.Application': Call was rejected by callee. 

Would appreciate very much for helping. Thanks
                    
                  </div>

                

                  <div class="Comment">
                  <div style="float:right;margin: 10px;">
                      Sly on 2/26/2009                      
                  </div>
                    Hi,

This script seem don't word with outlook 2003 / 2007.

Someone can help me ?

Thanks.
                    
                  </div>

                
    
        <div id="disqus_thread"><div style="overflow: hidden;"><div style="width: 54px; height: 54px; margin: 0px auto; overflow: hidden; background-image: url(&quot;&quot;); background-repeat: no-repeat;"><style type="text/css">.disqus-loader{animation:disqus-embed-spinner .7s infinite linear;-webkit-animation:disqus-embed-spinner .7s infinite linear}@keyframes disqus-embed-spinner{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}@-webkit-keyframes disqus-embed-spinner{0%{-webkit-transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg)}}</style><div class="disqus-loader" style="width: 29px; height: 29px; margin: 11px 14px; background-image: url(&quot;&quot;); background-repeat: no-repeat; background-position: -54px 0px;"></div></div><p align="center">Disqus seems to be taking longer than usual. <a href="#" onclick="DISQUS.reset({reload: true}); return false;">Reload</a>?</p></div><iframe verticalscrolling="no" horizontalscrolling="no" src="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/a.htm" style="width: 100%; border: medium none; overflow: hidden; height: 0px;" role="complementary" allowtransparency="true" data-disqus-uid="1" id="dsq1" frameborder="0" scrolling="no" width="100%"></iframe><iframe src="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/client.htm" style="width: 100%; border: medium none; overflow: hidden; height: 0px; display: none;" role="application" allowtransparency="true" data-disqus-uid="2" id="dsq2" frameborder="0" width="100%"></iframe></div>

        <script type="text/javascript">
        /**

        * var disqus_identifier; [Optional but recommended: Define a unique identifier (e.g. post id or slug) for this thread] 

        */
        (function () {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = 'http://wyniaorg.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();

        </script>

        <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript=wyniaorg">comments powered by Disqus.</a></noscript>

        
        
    
        



        





                    

    

        
        <hr>
        		
			
            
		</div>
                <div class="span-8 last">
                <center>
                    <img src="Creating%20Outlook%20Tasks%20with%20PHP%20-%20The%20Glass%20is%20Too%20Big%20-%20J%20Wynia_files/4794244574_142701d44c_m.jpg" style="text-align: center;margin-left: 45px;margin-top: 30px;border: solid 10px #FFFFFF;-moz-border-radius: 5px; -webkit-border-radius: 5px; -webkit-box-shadow: 0 1px 3px rgba(0,0,0, .4); -moz-box-shadow: 0 1px 3px rgba(0,0,0, .4);">
                </center>
                    
    <form action="/Article/Search" method="get" style="float: right; margin: 15px;">



    <dl>

        <dt>

            <label>

                Search</label>

        </dt>

        <dd>

            <input name="searchTerm" type="text">

        </dd>

        <dt></dt>

        <dd>

            <input value="Search" type="submit">

        </dd>

        <dt></dt>

        <dd>

            Or, browse <a href="http://www.wynia.org/Article/Archives">the archives</a>.

        </dd>

    </dl>

    </form>
   
   

                </div>
                 
        </div>
       


   <div id="FooterContainer">
    © 2003- 2013
    J Wynia. Very Few Rights Reserved. This article is licensed under 
the terms of the Creative Commons Attribution License. Quoted content or
 content included from others is not subject to that license and 
defaults to normal copyright.
</div>
        </div>
	</div>
    <script type="text/javascript">

        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-17990971-2']);
        _gaq.push(['_trackPageview']);

        (function () {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();

</script>


</body></html>